package com.sm.auth.service.impl;

import com.sm.auth.entity.UmsSysUser;
import com.sm.auth.mapper.UserMapper;
import com.sm.auth.vo.LoginUserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class SysUserDetailService implements UserDetailsService {

    @Autowired
    private UserMapper sysUserMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UmsSysUser sysUser = sysUserMapper.selectUserByUserName(username);
        log.info("用户信息：{}", sysUser);
        //根据角色获取权限
        LoginUserVo loginUserVo = new LoginUserVo();
        loginUserVo.setId(sysUser.getId());
        loginUserVo.setSysUser(sysUser);
        return loginUserVo;
    }
}
